package dmp.every;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class GetEveryTask extends Configuration implements Tool {

	@Override
	public void setConf(Configuration conf) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Configuration getConf() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int run(String[] args) throws Exception {
		Configuration conf=new Configuration();
		conf.set("mapreduce.job.queuename", "ven3"); //设置队列
		Job job = Job.getInstance(conf);
		
		job.setJobName("getEvery");
		job.setJarByClass(GetEveryTask.class);
		
		job.setMapperClass(GetEveryMapper.class);
		job.setReducerClass(GetEveryReduce.class);
		
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Text.class);
		
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(NullWritable.class);
		
		SequenceFileInputFormat.setInputPaths(job, new Path(args[0]));
		job.setInputFormatClass(SequenceFileInputFormat.class);
		
		
		Path out=new Path("/user/vendorwins/chenjinghui/every");
		FileOutputFormat.setOutputPath(job, out);
		
		FileSystem fs=FileSystem.get(new Configuration());
		if(fs.exists(out)){
			fs.delete(out, true);
		}
		
		return job.waitForCompletion(true)?0:1;
	}
	public static void main(String[] args) throws Exception {
		int rs=ToolRunner.run(new GetEveryTask(), args);
		if(rs==0){
			System.exit(0);
		}
	}

}
